package com.example.qcrmdemo.service.impl;

import com.example.qcrmdemo.dao.SalesPlanMapper;
import com.example.qcrmdemo.entity.SalesPlan;
import com.example.qcrmdemo.service.SalesPlanService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class SalesPlanServiceImpl implements SalesPlanService {

    @Autowired
    private SalesPlanMapper salesPlanMapper;

    @Override
    public PageInfo<SalesPlan> findByKeyword(int pageNum, int pageSize, String keyword) {
        PageHelper.startPage(pageNum,pageSize);
        List<SalesPlan> customers=salesPlanMapper.selectByKeyword(keyword);
        PageInfo<SalesPlan> pageInfo=new PageInfo<>(customers);
        return pageInfo;
    }

    @Override
    public SalesPlan findById(int id) {
        return salesPlanMapper.selectById(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean append(SalesPlan salesPlan) {
        return salesPlanMapper.insert(salesPlan)>0;
    }

    @Override
    public boolean modify(SalesPlan salesPlan) {
        return salesPlanMapper.updateById(salesPlan)>0;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean remove(int id) {
        return salesPlanMapper.deleteById(id)>0;
    }

    @Override
    public PageInfo<SalesPlan> selectAll() {
        final List<SalesPlan> salesPlans=salesPlanMapper.selectAll();
        PageInfo<SalesPlan> planInfo=new PageInfo<>(salesPlans);
        return planInfo;
    }
}
